package custom;

import java.awt.event.ActionListener;
import java.util.concurrent.TimeUnit;

import javax.swing.Timer;

public class Clock {
	public static final TimeUnit MILLISECONDS = TimeUnit.MILLISECONDS;
	public static final TimeUnit SECONDS = TimeUnit.SECONDS;
	public static final TimeUnit NANOSECONDS = TimeUnit.SECONDS;
	private static final long START = System.nanoTime();
	private Timer timer;

	public Clock(int duration, ActionListener listener) {
		timer = new Timer(duration, listener);
		timer.start();
	}

	private long time() {
		return System.nanoTime() - START;
	}

	public long getTime(TimeUnit timeUnit) {
		return timeUnit.convert(time(), TimeUnit.NANOSECONDS);
	}
}
